package com.kkshop.config;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.log4j.Logger;

@XmlRootElement(name = "configuration")
public class Configuration {
    
    private static final Logger log = Logger.getLogger(Configuration.class);
    
    private static Configuration _instance;

    @XmlElement(name = "server")
    private Server _server;
    
    public static Configuration getInstance() {
        return _instance;
    }
    
    static void initialize(InputStream inputStream) {
        try {
            JAXBContext jc = JAXBContext.newInstance(Configuration.class);
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            _instance = (Configuration) unmarshaller.unmarshal(inputStream);
        } catch(Exception e) {
            log.error("Could not set up configuration", e);
            throw new RuntimeException(e);
        }
    }

    public Server getServer() {
        return _server;
    }

    public void setServer(Server server) {
        _server = server;
    }
}
